
/*
 * Copyright (C) 2008-2009 Archie L. Cobbs. All rights reserved.
 *
 * $Id: XMLFieldSwitch.java 377 2010-03-11 20:50:18Z archie.cobbs $
 */

package org.dellroad.sidekar.xml;

import org.dellroad.sidekar.Item;
import org.dellroad.sidekar.ListField;
import org.dellroad.sidekar.MapField;
import org.dellroad.sidekar.SetField;

/**
 * Extracts a {@link org.dellroad.sidekar.Field Field}'s value and wraps it in an {@link XMLField} object.
 * This is used when marshalling the fields of an {@link Item}.
 */
class XMLFieldSwitch extends XMLSimpleFieldSwitch {

    public XMLFieldSwitch(Item<?> item) {
        super(item);
    }

    /**
     * Get the {@link XMLField} created during the previous "visit".
     */
    public XMLField getXMLField() {
        return this.xmlField;
    }

    public <E> void caseSetField(SetField<E> field) {
        this.xmlField = new XMLSetField<E>(this.item, field);
    }

    public <K, V> void caseMapField(MapField<K, V> field) {
        this.xmlField = new XMLMapField<K, V>(this.item, field);
    }

    public <E> void caseListField(ListField<E> field) {
        this.xmlField = new XMLListField<E>(this.item, field);
    }
}

